﻿using System.Collections.Generic;
using Orchard.Environment.Extensions.Models;
using Orchard.Security.Permissions;

namespace Orchard.Commerce
{
    public class Permissions : IPermissionProvider
    {
        public static readonly Permission ManageCommerce = new Permission { Description = "Managing Commerce", Name = "ManageCommerce" };
        public static readonly Permission AddCategory = new Permission { Description = "Add Category", Name = "AddCategory" };
        public static readonly Permission DeleteCategory = new Permission { Description = "Delete Category", Name = "DeleteCategory" };
        public static readonly Permission ReadCategory = new Permission { Description = "Read Category", Name = "ReadCategory" };
        public static readonly Permission EditCategory = new Permission { Description = "Edit Category", Name = "EditCategory" };
        public static readonly Permission AddProduct = new Permission { Description = "Add Product", Name = "AddProduct" };
        public static readonly Permission DeleteProduct = new Permission { Description = "Delete Product", Name = "DeleteProduct" };
        public static readonly Permission ReadProduct = new Permission { Description = "Read Product", Name = "ReadProduct" };
        public static readonly Permission EditProduct = new Permission { Description = "Edit Product", Name = "EditProduct" };
        public static readonly Permission AddShoppingCart = new Permission { Description = "Add Shopping Cart", Name = "AddShoppingCart" };
        public static readonly Permission DeleteShoppingCart = new Permission { Description = "Delete Shopping Cart", Name = "DeleteShoppingCart" };
        public static readonly Permission ReadShoppingCart = new Permission { Description = "Read Shopping Cart", Name = "ReadShoppingCart" };
        public static readonly Permission EditShoppingCart = new Permission { Description = "Edit Shopping Cart", Name = "EditShoppingCart" };
        public static readonly Permission AddSalesOrder = new Permission { Description = "Add Sales Order", Name = "AddSalesOrder" };
        public static readonly Permission DeleteSalesOrder = new Permission { Description = "Delete Sales Order", Name = "DeleteSalesOrder" };
        public static readonly Permission ReadSalesOrder = new Permission { Description = "Read Sales Order", Name = "ReadSalesOrder" };
        public static readonly Permission EditSalesOrder = new Permission { Description = "Edit Sales Order", Name = "EditSalesOrder" };
        public virtual Feature Feature { get; set; }

        public IEnumerable<Permission> GetPermissions()
        {
            return new Permission[] {
                ManageCommerce,
                AddCategory,
                DeleteCategory,
                DeleteCategory,
                ReadCategory,
                EditCategory,
                AddProduct,
                DeleteProduct,
                ReadProduct,
                EditProduct,
                AddShoppingCart,
                DeleteShoppingCart,
                ReadShoppingCart,
                EditShoppingCart,
                AddSalesOrder,
                DeleteSalesOrder,
                ReadSalesOrder,
                EditSalesOrder
            };
        }

        public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
        {
            return new[] {
                new PermissionStereotype {
                    Name = "Commerce Administrator",
                    Permissions = new[] { ManageCommerce }
                },
                new PermissionStereotype {
                    Name = "Commerce Shopper",
                    Permissions = new[] {
                        ReadCategory, 
                        ReadProduct, 
                        AddShoppingCart, 
                        DeleteShoppingCart, 
                        EditShoppingCart,
                        AddSalesOrder,
                        DeleteSalesOrder,
                        ReadSalesOrder,
                        EditSalesOrder
                    }
                },
                new PermissionStereotype {
                    Name = "Commerce Employee",
                    Permissions = new[] {
                        AddCategory,
                        DeleteCategory,
                        DeleteCategory,
                        ReadCategory,
                        EditCategory,
                        AddProduct,
                        DeleteProduct,
                        ReadProduct,
                        EditProduct,
                        AddSalesOrder,
                        DeleteSalesOrder,
                        ReadSalesOrder,
                        EditSalesOrder
                    }
                },
            };
        }

    }
}